package com.huonan.component.web;


import com.huonan.component.mysql.TbDictionary;
import com.huonan.component.sftp.SftpComment;
import com.huonan.component.web.service.RedisService;
import com.huonan.component.web.service.WebService;
import com.mz.social.common.web.annotation.BaseResponse;
import com.mz.social.common.web.model.JsonResponseWrapper;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/test")
@BaseResponse
@AllArgsConstructor
public class TestController {

    WebService webservice;
    RedisService redisService;
    SftpComment sftpComment;

    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    @GetMapping("cs")
    public long consumer() {
        long count = webservice.count();
        return count;
    }

    @GetMapping("/id/{id}")
    public TbDictionary consumer(@PathVariable int id) {
        return webservice.selectById(id);
    }

    @GetMapping("/name/{name}")
    public List<TbDictionary> selectByName(@PathVariable String name) {
        return webservice.selectByName(name);
    }

    @GetMapping("/list/{id}")
    public List<TbDictionary> selectByName(@PathVariable int id) {
        return webservice.selectListById(id);
    }

    @GetMapping("web")
    public JsonResponseWrapper<Integer> testCommon() {
        return JsonResponseWrapper.success(1);
    }
    @GetMapping("web2")
    public Integer testCommon2() {
       return webservice.exception();
    }

    @GetMapping("redis")
    public boolean redisTest1() {
        return redisService.testLock();
    }

    @GetMapping("sftp")
    public List<String> sftpTest1() {
        List<String> list = sftpComment.lsDirs("/");
        System.out.println(sftpComment);
        return list;
    }

    @PutMapping("ser/{value}")
    public void testSer(@PathVariable String value) {
        redisService.testStrSerialize(value);
    }
}


